﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FeCMS.AccessControlModule.Security;
using System.Web.Security;

namespace TestWeb
{
    public partial class LoginTest : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        public void CustomizeLogin()
        {
            
        }

        protected void LoginBtn_Click(object sender, EventArgs e)
        {
            // -----------------------------------------------------------------
            // 注意：演示代码为了简单，这里不检查用户名与密码是否正确。
            // -----------------------------------------------------------------

            string loginName = Request.Form["loginName"];
            if (string.IsNullOrEmpty(loginName))
                return;


            UserInfo userinfo = new UserInfo();
            userinfo.UserName = "ABC";
            userinfo.UserId = 9999;
            userinfo.RoleId = 888;


            // 登录状态100分钟内有效
            FeFormsPrincipal.SignIn(loginName, userinfo, 100);

            TryRedirect();


            //string loginName = Request.Form["loginName"];
            //if (string.IsNullOrEmpty(loginName))
            //    return;

            //FormsAuthentication.SetAuthCookie(loginName, true);

            //TryRedirect();

        }

        protected void OutBtn_Click(object sender, EventArgs e)
        {
            FeFormsPrincipal.SignOut();
            TryRedirect();
        }

        private void TryRedirect()
        {
            string returnUrl = Request.QueryString["ReturnUrl"];
            if (string.IsNullOrEmpty(returnUrl) == false)
            {
                Response.Redirect(returnUrl);
            }
            else
            {
                Response.Redirect("LoginTest.aspx");
            }
        }
    }
}